package com.ruoyi.web.controller.basedata;

import java.util.List;

import com.ruoyi.basedata.domain.WalletKind;
import com.ruoyi.basedata.service.IWalletKindService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 钱包种类 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-05
 */
@Controller
@RequestMapping("/basedata/walletkind")
public class WalletKindController extends BaseController
{
    private String prefix = "basedata/walletkind";
	
	@Autowired
	private IWalletKindService walletKindService;
	
	@RequiresPermissions("basedata:walletkind:view")
	@GetMapping()
	public String walletKind()
	{
	    return prefix + "/walletkind";
	}
	
	/**
	 * 查询钱包种类列表
	 */
	@RequiresPermissions("basedata:walletkind:list")
	@PostMapping("/list")
    @ResponseBody
	public TableDataInfo list(WalletKind walletKind)
	{
		startPage();
        List<WalletKind> list = walletKindService.selectWalletKindList(walletKind);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出钱包种类列表
	 */
	@RequiresPermissions("basedata:walletkind:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WalletKind walletKind)
    {
    	List<WalletKind> list = walletKindService.selectWalletKindList(walletKind);
        ExcelUtil<WalletKind> util = new ExcelUtil<WalletKind>(WalletKind.class);
        return util.exportExcel(list, "walletKind");
    }
	
	/**
	 * 新增钱包种类
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存钱包种类
	 */
	@RequiresPermissions("basedata:walletkind:add")
	@Log(title = "钱包种类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WalletKind walletKind)
	{		
		return toAjax(walletKindService.insertWalletKind(walletKind));
	}

	/**
	 * 修改钱包种类
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		WalletKind walletKind = walletKindService.selectWalletKindById(id);
		mmap.put("walletKind", walletKind);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存钱包种类
	 */
	@RequiresPermissions("basedata:walletkind:edit")
	@Log(title = "钱包种类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WalletKind walletKind)
	{		
		return toAjax(walletKindService.updateWalletKind(walletKind));
	}
	
	/**
	 * 删除钱包种类
	 */
	@RequiresPermissions("basedata:walletkind:remove")
	@Log(title = "钱包种类", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(walletKindService.deleteWalletKindByIds(ids));
	}


	/**
	 * 银行钱包修改
	 */
	@Log(title = "钱包种类", businessType = BusinessType.UPDATE)
	@RequiresPermissions("basedata:walletkind:eidt")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(WalletKind walletKind) {
		return toAjax(walletKindService.changeStatus(walletKind));
	}

	/**
	 * 校验名字
	 */
	@PostMapping("/checkWalletkindUnique")
	@ResponseBody
	public String checkWalletkindUnique(WalletKind walletKind) {
		return walletKindService.checkWalletkindUnique(walletKind);
	}
}
